package com.lyy.king.common.utils.utils;


import org.dozer.DozerBeanMapper;

import java.util.ArrayList;
import java.util.List;

public class  BeanFactoryUtils {
    /**
     * 列表拷贝
     * @param list
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> List<T> copyPropertiesList(List<?> list, Class<T> clazz) {
        DozerBeanMapper mapper = new DozerBeanMapper();
        List<T> result = new ArrayList<>(list.size());
        for (Object source : list) {
            T target = mapper.map(source, clazz);
            result.add(target);
        }
        return result;
    }

    /**
     * 属性拷贝
     * @param source
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T copyProperties(Object source, Class<T> clazz) {
        DozerBeanMapper mapper = new DozerBeanMapper();

        T target = mapper.map(source, clazz);

        return target;
    }
}
